package com.example.financeapi.config;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
 * 获取异常类型
 * @author Alvin
 */
public class ExceptionExample {

    @SuppressWarnings("null")
    public static void main(String[] args) {
        String text = null;
        try {
            //InputStream is =new ByteArrayInputStream(text.getBytes("UTF-8"));
        } catch (Exception e) {
            System.out.println("引起异常的原因------>"+getExceptionType(e));
            System.out.println("异常信息------>"+getExceptionMessage(e));
            System.out.println("异常跟踪栈------>"+getExceptionSrintStackTrace(e));
        }
    }
    public static Throwable getExceptionType(Exception e) {
        return e;
    }
    public static String getExceptionMessage(Exception e) {
        return e.getMessage();
    }
    public static String getExceptionSrintStackTrace(Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
    public static int number() {
        return 10/0;
    }
}